package com.hky.algorithm.mahjongGame;

import com.hky.algorithm.realize.Type;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.Objects;

/**
 * 一张牌
 */
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Card implements Comparable<Card> {
    public int num;
    public Type type;

    /**
     * 使用String类型type实例化
     *
     * @param num  数字
     * @param type 类型
     */
    public Card(int num, String type) {
        this.num = num;
        this.type = Type.valueOf(type);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Card card = (Card) o;
        return num == card.num && type == card.type;
    }

    @Override
    public int hashCode() {
        return Objects.hash(num, type);
    }

    @Override
    public int compareTo(Card card) {
        return card.type == this.type ? this.num - card.num : this.type.ordinal() - card.type.ordinal();
    }
}
